package data.hierarchy;

import java.util.ArrayList;
import java.util.List;

import data.base.PointLight;
import data.base.Vertex;
import data.complex.Camera;
import data.complex.Triangle;

public class World implements IVertexProvider{
  private List<Mesh> meshes = new ArrayList<Mesh>();
  private List<PointLight> pointLights = new ArrayList<PointLight>();
  private Camera camera;
  private List<Vertex> pointsCache;
  
  public World(){
  }
  
  public List<Mesh> getMeshes() {
    return meshes;
  }

  public void addMesh(Mesh mesh) {
    meshes.add(mesh);
  }
  
  public void addPointLight(PointLight light){
    pointLights.add(light);
  }
  
  public List<PointLight> getPointLights() {
    return pointLights;
  }

  public Camera getCamera() {
    return camera;
  }

  public void setCamera(Camera camera) {
    this.camera = camera;
  }

  @Override
  public Iterable<Vertex> getVertices() {
    if(pointsCache == null){
      pointsCache = new ArrayList<Vertex>();
      for(Mesh m : getMeshes()){
        for(TriangleGroup tg : m){
          for(Triangle t : tg){
            pointsCache.add(t.getA());
            pointsCache.add(t.getB());
            pointsCache.add(t.getC());
          }
        }
      }
    }
    return pointsCache;
  }  
}
